<%_ 
function getResponseType(api) {
  if (api.response && api.response.length > 0) {
    if (api.type === 'list') {
      return 'CursorPageData<' + api.structName.response + '>';
    } else {
      return api.response;
    }
  } else if (api.type === 'add') {
    return 'IDRes';
  } else {
    return '()';
  }
}
_%> 
use salvo::{
    oapi::{endpoint, extract::PathParam},
    Depot, Writer,
};
use rsns_common::{
    context::Context,
    error::{AppError, Error},
    request::JsonBody,
    res::{PageData, PageParams},
    response::AppResponse,
    transform,
};
use crate::model::<%= data.name %>::*;
use crate::service::<%= data.name %>_service;

<% data.endpoints.forEach(function(api) { %>
/// <%= api.summary _%>
<% if (api.method === 'GET' && api.structName.params.length > 0) { %>
#[endpoint(tags("<%= data.tags %>"), parameters(<%= api.structName.params %>))]
<% } else { %>
#[endpoint(tags("<%= data.tags %>"))]
<% } _%>
pub async fn <%= api.controller_name %>(
    depot: &mut Depot
) -> Result<AppResponse<<%=getResponseType(api)_%>>, AppError>{
    let ctx = depot.obtain_mut::<Context>().unwrap();

    let result = <%= data.name %>_service::<%= api.service_name %>(ctx, page, params.to_owned()).await;
    Ok(AppResponse(result))
}
<% }); %>